package com.jindy.module.receiptorder.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.jindy.common.core.domain.entity.SysUser;
import com.jindy.common.utils.SecurityUtils;
import com.jindy.module.receiptorder.domain.ReceiptOrder;
import com.jindy.module.receiptorder.service.IReceiptOrderService;
import com.jindy.system.service.ISysUserService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jindy.common.annotation.Log;
import com.jindy.common.core.controller.BaseController;
import com.jindy.common.core.domain.AjaxResult;
import com.jindy.common.enums.BusinessType;
import com.jindy.common.utils.poi.ExcelUtil;
import com.jindy.common.core.page.TableDataInfo;

/**
 * 【入库订单】Controller
 *
 * @author ruoyi
 * @date 2022-10-12
 */
@RestController
@RequestMapping("/module/receiptOorder")
public class ReceiptOrderController extends BaseController
{
    @Autowired
    private IReceiptOrderService receiptOrderService;
    @Autowired
    private ISysUserService sysUserService;

    /**
     * 查询【入库订单】列表
     */
    @GetMapping("/list")
    @PreAuthorize("@ss.hasPermi('module:receiptOorder:list')")
    public TableDataInfo list(ReceiptOrder receiptOrder)
    {
        //添加权限
        SysUser sysUser = SecurityUtils.getLoginUser().getUser();
        receiptOrder.setUserId(sysUser.getUserId());

        startPage();
        List<ReceiptOrder> list = receiptOrderService.selectReceiptOrderList(receiptOrder);
        return getDataTable(list);
    }

    /**
     * 导出【入库订单】列表
     */
    @Log(title = "【入库订单】", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('module:receiptOorder:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, ReceiptOrder receiptOrder)
    {
        //添加权限
        SysUser sysUser = SecurityUtils.getLoginUser().getUser();
        receiptOrder.setUserId(sysUser.getUserId());

        List<ReceiptOrder> list = receiptOrderService.selectReceiptOrderList(receiptOrder);
        ExcelUtil<ReceiptOrder> util = new ExcelUtil<ReceiptOrder>(ReceiptOrder.class);
        util.exportExcel(response, list, "【入库订单】数据");
    }

    /**
     * 获取【入库订单】详细信息
     */
    @PreAuthorize("@ss.hasPermi('module:receiptOorder:id')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(receiptOrderService.selectReceiptOrderById(id));
    }

    /**
     * 新增【入库订单】
     */
    @Log(title = "【入库订单】", businessType = BusinessType.INSERT)
    @PreAuthorize("@ss.hasPermi('module:receiptOorder:add')")
    @PostMapping
    public AjaxResult add(@RequestBody ReceiptOrder receiptOrder)
    {
        return toAjax(receiptOrderService.insertReceiptOrder(receiptOrder));
    }

    /**
     * 修改【入库订单】
     */
    @Log(title = "【入库订单】", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('module:receiptOorder:update')")
    @PutMapping
    public AjaxResult edit(@RequestBody ReceiptOrder receiptOrder)
    {
        return toAjax(receiptOrderService.updateReceiptOrder(receiptOrder));
    }

    /**
     * 删除【入库订单】
     */
    @Log(title = "【入库订单】", businessType = BusinessType.DELETE)
    @PreAuthorize("@ss.hasPermi('module:receiptOorder:delete')")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(receiptOrderService.deleteReceiptOrderByIds(ids));
    }
}
